home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / cool.lha / ice / pisces / flex / flex.skl < prev    next >
Encoding:
Text File  |  1991-09-04  |  11.7 KB  |  527 lines

  1. /* A lexical scanner generated by flex */
  2.  
  3. /* scanner skeleton version:
  4.  * $Header: /tan/u1/ice/pisces/flex/RCS/flex.skl,v 1.1 91/02/06 15:05:47 fontana Exp $
  5.  */
  6.  
  7. #include <stdio.h>
  8.  
  9. #define FLEX_SCANNER
  10.  
  11. /* amount of stuff to slurp up with each read */
  12. #ifndef YY_READ_BUF_SIZE
  13. #define YY_READ_BUF_SIZE 8192
  14. #endif
  15.  
  16. #ifndef YY_BUF_SIZE
  17. #define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of input buffer */
  18. #endif
  19.  
  20. /* returned upon end-of-file */
  21. #define YY_END_TOK 0
  22.  
  23. /* copy whatever the last rule matched to the standard output */
  24.  
  25. #define ECHO fputs( yytext, yyout )
  26.  
  27. /* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
  28.  * is returned in "result".
  29.  */
  30. #define YY_INPUT(buf,result,max_size) \
  31.     if ( (result = read( fileno(yyin), buf, max_size )) < 0 ) \
  32.         YY_FATAL_ERROR( "read() in flex scanner failed" );
  33. #define YY_NULL 0
  34. #define yyterminate() return ( YY_NULL )
  35.  
  36. /* report a fatal error */
  37. #define YY_FATAL_ERROR(msg) \
  38.     { \
  39.     fputs( msg, stderr ); \
  40.     putc( '\n', stderr ); \
  41.     exit( 1 ); \
  42.     }
  43.  
  44. /* default yywrap function - always treat EOF as an EOF */
  45. #define yywrap() 1
  46.  
  47. /* enter a start condition.  This macro really ought to take a parameter,
  48.  * but we do it the disgusting crufty way forced on us by the ()-less
  49.  * definition of BEGIN
  50.  */
  51. #define BEGIN yy_start = 1 + 2 *
  52.  
  53. /* action number for EOF rule of a given start state */
  54. #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
  55.  
  56. /* special action meaning "start processing a new file" */
  57. #define YY_NEW_FILE goto new_file
  58.  
  59. /* default declaration of generated scanner - a define so the user can
  60.  * easily add parameters
  61.  */
  62. #ifdef __STDC__
  63. #define YY_DECL int yylex( void )
  64. #else
  65. #define YY_DECL int yylex()
  66. #endif
  67.  
  68. /* code executed at the end of each rule */
  69. #define YY_BREAK break;
  70.  
  71. #define YY_END_OF_BUFFER_CHAR 0
  72.  
  73. /* done after the current pattern has been matched and before the
  74.  * corresponding action - sets up yytext
  75.  */
  76. #define YY_DO_BEFORE_ACTION \
  77.     yytext = yy_bp; \
  78.     yy_hold_char = *yy_cp; \
  79.     *yy_cp = '\0'; \
  80.     yy_c_buf_p = yy_cp;
  81.  
  82. /* returns the length of the matched text */
  83. #define yyleng (yy_cp - yy_bp)
  84.  
  85. #define EOB_ACT_RESTART_SCAN 0
  86. #define EOB_ACT_END_OF_FILE 1
  87. #define EOB_ACT_LAST_MATCH 2
  88.  
  89. /* return all but the first 'n' matched characters back to the input stream */
  90. #define yyless(n) \
  91.     { \
  92.     *yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \
  93.     yy_c_buf_p = yy_cp = yy_bp + n; \
  94.     YY_DO_BEFORE_ACTION; /* set up yytext again */ \
  95.     }
  96.  
  97. #define unput(c) yyunput( c, yy_bp )
  98.  
  99. #define YY_USER_ACTION
  100.  
  101. FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
  102. char *yytext;
  103.  
  104. #ifndef __STDC__
  105. #  ifndef __cplusplus
  106. #    define const
  107. #  endif
  108. #endif
  109.  
  110. %% section 1 code and the data tables for the DFA go here
  111.  
  112. /* these variables are all declared out here so that section 3 code can
  113.  * manipulate them
  114.  */
  115. static char *yy_c_buf_p;    /* points to current character in buffer */
  116. static int yy_init = 1;        /* whether we need to initialize */
  117. static int yy_start = 0;    /* start state number */
  118.  
  119. /* true when we've seen an EOF for the current input file */
  120. static int yy_eof_has_been_seen;
  121.  
  122. static int yy_n_chars;        /* number of characters read into yy_ch_buf */
  123.  
  124. /* yy_ch_buf has to be 2 characters longer than YY_BUF_SIZE because we need
  125.  * to put in 2 end-of-buffer characters (this is explained where it is
  126.  * done) at the end of yy_ch_buf
  127.  */
  128. static char yy_ch_buf[YY_BUF_SIZE + 2];
  129.  
  130. /* yy_hold_char holds the character lost when yytext is formed */
  131. static char yy_hold_char;
  132.  
  133. static yy_state_type yy_last_accepting_state;
  134. static char *yy_last_accepting_cpos;
  135.  
  136. #ifdef __STDC__
  137. #  ifdef __cplusplus
  138. static yy_state_type yy_get_previous_state();
  139. static int yy_get_next_buffer();
  140. static void yyunput( int c, char *buf_ptr );
  141. static int flex_input();
  142. static void yyrestart( FILE *input_file );
  143. #  else
  144. static yy_state_type yy_get_previous_state( void );
  145. static int yy_get_next_buffer( void );
  146. static void yyunput( int c, char *buf_ptr );
  147. static int input( void );
  148. static void yyrestart( FILE *input_file );
  149. #  endif
  150. #else
  151. static yy_state_type yy_get_previous_state();
  152. static int yy_get_next_buffer();
  153. static void yyunput();
  154. static int input();
  155. static void yyrestart();
  156. #endif
  157.  
  158. YY_DECL
  159.     {
  160.     register yy_state_type yy_current_state;
  161.     register char *yy_cp, *yy_bp;
  162.     register int yy_act;
  163.  
  164. %% user's declarations go here
  165.  
  166.     if ( yy_init )
  167.     {
  168.     if ( ! yy_start )
  169.         yy_start = 1;    /* first start state */
  170.  
  171.     if ( ! yyin )
  172.         yyin = stdin;
  173.  
  174.     if ( ! yyout )
  175.         yyout = stdout;
  176.  
  177. new_file:
  178.     /* this is where we enter upon encountering an end-of-file and
  179.      * yywrap() indicating that we should continue processing
  180.      */
  181.  
  182.     /* we put in the '\n' and start reading from [1] so that an
  183.      * initial match-at-newline will be true.
  184.      */
  185.  
  186.     yy_ch_buf[0] = '\n';
  187.     yy_n_chars = 1;
  188.  
  189.     /* we always need two end-of-buffer characters.  The first causes
  190.      * a transition to the end-of-buffer state.  The second causes
  191.      * a jam in that state.
  192.      */
  193.     yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  194.     yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  195.  
  196.     yy_eof_has_been_seen = 0;
  197.  
  198.     yytext = yy_c_buf_p = &yy_ch_buf[1];
  199.     yy_hold_char = *yy_c_buf_p;
  200.     yy_init = 0;
  201.     }
  202.  
  203.     while ( 1 )        /* loops until end-of-file is reached */
  204.     {
  205.     yy_cp = yy_c_buf_p;
  206.  
  207.     /* support of yytext */
  208.     *yy_cp = yy_hold_char;
  209.  
  210.     /* yy_bp points to the position in yy_ch_buf of the start of the
  211.      * current run.
  212.      */
  213. %% yymore()-related code goes here
  214.  
  215. %% code to set up and find next match goes here
  216.  
  217.     /* bogus while loop to let YY_BACK_TRACK, EOB_ACT_LAST_MATCH,
  218.      * and EOF actions branch here without introducing an optimizer-
  219.      * daunting goto
  220.      */
  221.     while ( 1 )
  222.         {
  223. %% code to find the action number goes here
  224.  
  225.         YY_DO_BEFORE_ACTION;
  226.         YY_USER_ACTION;
  227.  
  228. #ifdef FLEX_DEBUG
  229.         fprintf( stderr, "--accepting rule #%d (\"%s\")\n",
  230.              yy_act, yytext );
  231. #endif
  232.  
  233. do_action:    /* this label is used only to access EOF actions */
  234.         switch ( yy_act )
  235.         {
  236. %% actions go here
  237.  
  238.         case YY_END_OF_BUFFER:
  239.             /* undo the effects of YY_DO_BEFORE_ACTION */
  240.             *yy_cp = yy_hold_char;
  241.  
  242.             yytext = yy_bp;
  243.  
  244.             switch ( yy_get_next_buffer() )
  245.             {
  246.             case EOB_ACT_END_OF_FILE:
  247.                 {
  248.                 if ( yywrap() )
  249.                 {
  250.                 /* note: because we've taken care in
  251.                  * yy_get_next_buffer() to have set up yytext,
  252.                  * we can now set up yy_c_buf_p so that if some
  253.                  * total hoser (like flex itself) wants
  254.                  * to call the scanner after we return the
  255.                  * YY_NULL, it'll still work - another YY_NULL
  256.                  * will get returned.
  257.                  */
  258.                 yy_c_buf_p = yytext;
  259.  
  260.                 yy_act = YY_STATE_EOF((yy_start - 1) / 2);
  261.                 goto do_action;
  262.                 }
  263.  
  264.                 else
  265.                 YY_NEW_FILE;
  266.                 }
  267.                 break;
  268.  
  269.             case EOB_ACT_RESTART_SCAN:
  270.                 yy_c_buf_p = yytext;
  271.                 yy_hold_char = *yy_c_buf_p;
  272.                 break;
  273.  
  274.             case EOB_ACT_LAST_MATCH:
  275.                 yy_c_buf_p = &yy_ch_buf[yy_n_chars];
  276.  
  277.                 yy_current_state = yy_get_previous_state();
  278.  
  279.                 yy_cp = yy_c_buf_p;
  280.                 yy_bp = yytext;
  281.                 continue; /* go to "YY_DO_BEFORE_ACTION" */
  282.             }
  283.             break;
  284.  
  285.         default:
  286.             printf( "action # %d\n", yy_act );
  287.             YY_FATAL_ERROR( "fatal flex scanner internal error" );
  288.         }
  289.  
  290.         break; /* exit bogus while loop */
  291.         }
  292.     }
  293.     }
  294.  
  295.  
  296. /* yy_get_next_buffer - try to read in new buffer
  297.  *
  298.  * synopsis
  299.  *     int yy_get_next_buffer();
  300.  *     
  301.  * returns a code representing an action
  302.  *     EOB_ACT_LAST_MATCH - 
  303.  *     EOB_ACT_RESTART_SCAN - restart the scanner
  304.  *     EOB_ACT_END_OF_FILE - end of file
  305.  */
  306.  
  307. static int yy_get_next_buffer()
  308.  
  309.     {
  310.     register char *dest = yy_ch_buf;
  311.     register char *source = yytext - 1; /* copy prev. char, too */
  312.     register int number_to_move, i;
  313.     int ret_val;
  314.     
  315.     if ( yy_c_buf_p != &yy_ch_buf[yy_n_chars + 1] )
  316.     {
  317.     YY_FATAL_ERROR( "NULL in input" );
  318.     /*NOTREACHED*/
  319.     }
  320.  
  321.     /* try to read more data */
  322.  
  323.     /* first move last chars to start of buffer */
  324.     number_to_move = yy_c_buf_p - yytext;
  325.  
  326.     for ( i = 0; i < number_to_move; ++i )
  327.     *(dest++) = *(source++);
  328.  
  329.     if ( yy_eof_has_been_seen )
  330.     /* don't do the read, it's not guaranteed to return an EOF,
  331.      * just force an EOF
  332.      */
  333.     yy_n_chars = 0;
  334.  
  335.     else
  336.     {
  337.     int num_to_read = YY_BUF_SIZE - number_to_move - 1;
  338.  
  339.     if ( num_to_read > YY_READ_BUF_SIZE )
  340.         num_to_read = YY_READ_BUF_SIZE;
  341.  
  342.     /* read in more data */
  343.     YY_INPUT( (&yy_ch_buf[number_to_move]), yy_n_chars, num_to_read );
  344.     }
  345.  
  346.     if ( yy_n_chars == 0 )
  347.     {
  348.     if ( number_to_move == 1 )
  349.         ret_val = EOB_ACT_END_OF_FILE;
  350.     else
  351.         ret_val = EOB_ACT_LAST_MATCH;
  352.  
  353.     yy_eof_has_been_seen = 1;
  354.     }
  355.  
  356.     else
  357.     ret_val = EOB_ACT_RESTART_SCAN;
  358.  
  359.     yy_n_chars += number_to_move;
  360.     yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  361.     yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  362.  
  363.     /* yytext begins at the second character in
  364.      * yy_ch_buf; the first character is the one which
  365.      * preceded it before reading in the latest buffer;
  366.      * it needs to be kept around in case it's a
  367.      * newline, so yy_get_previous_state() will have
  368.      * with '^' rules active
  369.      */
  370.  
  371.     yytext = &yy_ch_buf[1];
  372.  
  373.     return ( ret_val );
  374.     }
  375.  
  376.  
  377. /* yy_get_previous_state - get the state just before the EOB char was reached
  378.  *
  379.  * synopsis
  380.  *     yy_state_type yy_get_previous_state();
  381.  */
  382.  
  383. static yy_state_type yy_get_previous_state()
  384.  
  385.     {
  386.     register yy_state_type yy_current_state;
  387.     register char *yy_cp;
  388.  
  389. %% code to get the start state into yy_current_state goes here
  390.  
  391.     for ( yy_cp = yytext; yy_cp < yy_c_buf_p; ++yy_cp )
  392.     {
  393. %% code to find the next state goes here
  394.     }
  395.  
  396.     return ( yy_current_state );
  397.     }
  398.  
  399.  
  400. #ifdef __STDC__
  401. #  ifdef __cplusplus
  402. static void yyunput( int c, char *yy_bp )
  403. #  else
  404. static void yyunput( int c, register char *yy_bp )
  405. #  endif
  406. #else
  407. static void yyunput( c, yy_bp )
  408. int c;
  409. register char *yy_bp;
  410. #endif
  411.  
  412.  
  413.     {
  414.     register char *yy_cp = yy_c_buf_p;
  415.  
  416.     *yy_cp = yy_hold_char; /* undo effects of setting up yytext */
  417.  
  418.     if ( yy_cp < yy_ch_buf + 2 )
  419.     { /* need to shift things up to make room */
  420.     register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
  421.     register char *dest = &yy_ch_buf[YY_BUF_SIZE + 2];
  422.     register char *source = &yy_ch_buf[number_to_move];
  423.  
  424.     while ( source > yy_ch_buf )
  425.         *--dest = *--source;
  426.  
  427.     yy_cp += dest - source;
  428.     yy_bp += dest - source;
  429.  
  430.     if ( yy_cp < yy_ch_buf + 2 )
  431.         YY_FATAL_ERROR( "flex scanner push-back overflow" );
  432.     }
  433.  
  434.     if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
  435.     yy_cp[-2] = '\n';
  436.  
  437.     *--yy_cp = c;
  438.  
  439.     YY_DO_BEFORE_ACTION; /* set up yytext again */
  440.     }
  441.  
  442.  
  443. #ifdef __cplusplus
  444. static int flex_input()
  445. #else
  446. static int input()
  447. #endif
  448.     {
  449.     int c;
  450.     char *yy_cp = yy_c_buf_p;
  451.  
  452.     *yy_cp = yy_hold_char;
  453.  
  454.     if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
  455.     { /* need more input */
  456.     yytext = yy_c_buf_p;
  457.     ++yy_c_buf_p;
  458.  
  459.     switch ( yy_get_next_buffer() )
  460.         {
  461.         /* this code, unfortunately, is somewhat redundant with
  462.          * that above
  463.          */
  464.         case EOB_ACT_END_OF_FILE:
  465.         {
  466.         if ( yywrap() )
  467.             {
  468.             yy_c_buf_p = yytext;
  469.             return ( EOF );
  470.             }
  471.  
  472.         yy_ch_buf[0] = '\n';
  473.         yy_n_chars = 1;
  474.         yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  475.         yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  476.         yy_eof_has_been_seen = 0;
  477.         yytext = yy_c_buf_p = &yy_ch_buf[1];
  478.         yy_hold_char = *yy_c_buf_p;
  479. #ifdef __cplusplus
  480.         return ( flex_input() );
  481. #else
  482.         return ( input() );
  483. #endif
  484.         }
  485.         break;
  486.  
  487.         case EOB_ACT_RESTART_SCAN:
  488.         yy_c_buf_p = yytext;
  489.         break;
  490.  
  491.         case EOB_ACT_LAST_MATCH:
  492. #ifdef __cplusplus
  493.         YY_FATAL_ERROR( "unexpected last match in flex_input()" );
  494. #else
  495.         YY_FATAL_ERROR( "unexpected last match in input()" );
  496. #endif
  497.         }
  498.     }
  499.  
  500.     c = *yy_c_buf_p;
  501.     yy_hold_char = *++yy_c_buf_p;
  502.  
  503.     return ( c );
  504.     }
  505.  
  506.  
  507. #ifdef __STDC__
  508. #  ifdef __cplusplus
  509. static void yyrestart( FILE *input_file )
  510. #  else
  511. static void yyrestart( FILE *input_file )
  512. #  endif
  513. #else
  514. static void yyrestart( input_file )
  515. FILE *input_file;
  516. #endif
  517.  
  518.     {
  519.     if ( yyin != stdin )
  520.     fclose( yyin );
  521.  
  522.     yyin = input_file;
  523.     yy_init = 1;
  524.     }
  525.  
  526.  
  527.